Started refactoring of stop command.
Refactoring and added some unit tests.