Make the script more robust with conditinal validations