Various bugs / imperfections spotted by pycharm.
fixes
lint
Merge pull request #301 from gbin/various-refactorings

Various bugs / imperfections spotted by pycharm.