Added error handling, checking, and validations