Add haddock comments for all important functions

This is just to have a mind-map for me and whoever reads this code
later.