Changed algorithm - Break out of first loop as soon as a match is found