updated sort compare function