add type check for compare function