improve packCommand function performance