improving validation and error handling