reorgenized the script

Also added docstrings and such...
added pycharm env.