Added comments to clarify while loop function.