Fix some error handling cases