Rewrite TOC merge to work better with upcoming rip refactoring