Double click interactive session related issue

Hi! My code is working fine for single clicks, which I am using to add a new centroid point. But it’s not properly working for double click. Using the double-click, I want to remove some of the existing centroid points (green dots inside the small circles) from the above image. As of now, double-clicking removes some elements from the main array, but that is not what I am expecting. First one or two results after double click seems fine but after that problem arise.
Any help will be highly appreciated.
My notebook link: Organize centroid points into Array Structure / JS | Observable
I’m talking about else if condition of remove_intsession.

The onclick might be triggered twice for each click, mousedown and mouseup

To detect the double click you might want to setup a dblclick event

Also adding invalidation could help to remove event listeners when the code is changed.