Roblem with custom code on linking table of content section for blog

https://www.flashfeed.io/blog/the-3-pillars-of-content-creation#toc-6

https://preview.webflow.com/preview/flashfeedio?utm_medium=preview_link&utm_source=designer&utm_content=flashfeedio&preview=6f9d1f8b28ce5974f2ff27bc5624f287&pageId=60a2150306d44a7f38ff4a7e&itemId=60a22df56d63962c20fd6b11&workflow=preview

I’m trying to build the table of contents sections on the sidebar to update on scroll. It’s working but I can’t get it to respond appropriately. Scrolling sometimes doesn’t work, only updates after scrolling up and down, and some secitons won’t link. It’s quite difficult. Could someone help me?