fixed script generation, added a few validations