Refactored version of smart-operator.