tidied code and updated docs