Refactoring: extracted some code from commands to operations