let sort_by_cat examples =
   (* sort according to category *)
   let sorted = sort (fun x -> x.ex_category) examples in
   (* clean up by seperating data and categories *)
   (* since categories are the same in each list, we just have to look up the category of the list head *)
   (* then we descend into the real data using List.rev_map *)
   let simplyfied = List.rev_map (fun x -> ((List.hd x).ex_category,List.rev_map (fun y ->y.ex_data) x)) sorted in
   simplyfied