general bug fixes found by pycheck and pylint