upgrade compare function and add some test