I'm a moron..
* make code actually valid
* cleaned up while loops