improving merge logic