added link to PyPi
Added some comments.
moving fragile stuff into individual functions
added overwrite option
Simplified loop termination condition.