Some reformulations and documentation

Hi Emil and Patrick,

reading your code, I added some documentation as I understood the code, and reformulated parts of it in order to made it easier to comprehend (at least from my perspective).

Feel free to pick what you like.

Cheers,
Andreas