Made better use of monad functions to simplify some of the definitions, especially by using Prelude.sequence.