code and docstring tidying