Refactors TOC code