Getting tests for each command ready, and some general refactoring