Refactoring: moved command handling code into own class.