Improved code and logic of command builder