replace hashCode function with compareTo