error handling and model validation