Improved the implementation and refactored the tests for the compare functionality