Rejiggered error handling. Made all tests pass.