new version with faster comparison