applied various code fix thanks to pycharm inspector