Add intelligence to compare function