refactor cmp function to closure function