I'm looking for sugestions on how to better structure this code.  I stuck it in a pastbin:

https://pastebin.com/gQFmvq6W/

Would a State monad help?

Thanks!