Update docstrings, cleanup and refactoring