fix bugs in Compare function
add more tests