Changed while to if
Merge pull request #447 from jsight/master

Changed while to if