Somewhat cleaner haskell with IOExceptions instead