General cleanup

* more readable shebang
* removed trailing whitespace
* fixed some indentation which was slightly off
* added docstrings (code is now 100% documented)
* made while-loop condition more pythonic