Refactor toc extraction