backport modifyIORef'