Add Validate function, Change generate function
Change valication map variable to global.