various code cleanup, docstrings etc.