Changed if statement to while.