finish compare function