Fixing comparator ("java.lang.IllegalArgumentException: Comparison method violates its general contract!")