Made the code less exception-happy