Update the algorithm of TOC generation
Update-add tests