switch some boring do notation to applicative syntax, split some functions to an helper module, and random cosmetic changes