Fixed compare function.
Code cleanup.