removed unused functions
added comparator optimization