Fixed the loop problem in the code.