Rewrite parts of the implementation to make it easier to read.
Add some more text to the documentation.

This is based on feedback by Thomas Richter on the mailing list.