fixed compare function