Fixed bug in compareTo method