r23552: Use proper comparison function an fix logic.