changed comparator to a function