Generalize methods to use MonadIO class, and bracket exceptions in the computation.