Refactor pattern_executor.