Generalize over MonadIO
Merge master into new-api (using imerge)