perf refactoring for merge