better error handling for model