Fixes #12

Moved code to While loop. Why I didn't do that before I have no idea.