Use IORef instead of State monad
Use IntMap over Map (requires unsafeCoerce)