Extended compare function.