Refactoring the invoke method.