Replace MVar with IORef and MVar lock