Updated the comments & corrected the loop bug