Docs and formatting.

Added haddock comments plus some tidying.