add validation and error handling