implemented the compare function