add comparison function.
optimize the code.