Refactored rank comparison