Misc refactor

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