general tidying and adding docstrings