Code cleanup; Haddock documentation