small refactor, and adding docstrings to functions and namespaces