handling errors and validations