fixed the string matching to end the loop