Refactored command class code.
Added more tests.