compare function corrected