Improved comparison algorithm.