revise the compareTo algorithm