Corrected a bug where the state of a command was set to Finished before
the execution was finished. Added tests for this case