Simplify while loop

Moves the `shift` and command logic out of the while loop.