Tidy up code so there are no side-effects on import that cause problems with pydoc