tested and completely fixed comparator