Make new compare() method more reliable.

Acknowledgement: This work has been supported in part by the "QIICR" project.