various improvements and corrections suggested by pycharm (not exhaustive)