Misc refactor

This fixes some miscellaneous issues I saw while doing other things, mostly from static analysis via Pylint.
last one