Better data input validation and error handling