optimize code and validation