Fix faulty error handling