Various bug fixes in generating command sequences.