added comparator, refactored source and tests