877-Don't reverse the command list.

Also neaten import.
877-Add unit test to check that the problem is fixed.