refactor dispatching of commands