state monad work - including StackOverflow answer
resolved merge