Fixed broken error handling