Changed ref compare algorithm