Refactor of CommandHandler.