refactored size comparison logic