refactor code to extract the command bus