Fixed compare function