added some validations and code