Reverted while-loop

Reverted while-loop into do-while loop and added a comment explaining why this was done