Split into multiple modules, document, and annotate for safe Haskell.