Fixing messy exception handling