General cleanup, renaming and bug fixes.

Indentation level now resets after a multiline type signature.
Indentation is maintained after blank lines.
Comments in between multiline type signatures are left at the correct indent.
Split many parts into their own helper functions.