Optimized the invoke method.