updated comparison algorithm