adds toc and formats code