Detect valid sequence of commands