Refactoring MsgGen.hs