Optimize RoutineEvent and FunctionEvent