refactored value comparison logic