Fixed compareTo function