Migration from StateT to ReaderT + IORef

This change was made to easily handle cases with asynchronous exceptions
arising in IO sections of the code.
This allows access to the latest state even in exception handlers.