Add some docstrings.
Refactor some string-manipulation functions, add documentation comments.