Do not use assigned names "next" and "id", rename to order_toc_list and clean up code