Refactoring of code from "Refactoring Monads - Haskell from Scratch #5"