Generalize to MonadIO instead of just IO