modified compare function