fix broken error handling