WIP: docstrings and some small refactorings.