sped up and compressed command generation code