Refactored equality tests to reduce complexity