command generation algorithm