Move toc code into openToc function