Refactoring of Compare code