Refactoring the comparison code to make it a little more generic.