finally fixed the comparing function