change assert to formal error handling