refactoring of the command listener