refactored compare to return a numeric value instead of an object