--UPDATE--
I think the problem was there was a glitch where sometimes placing 1 gear was actually placing 2, and this triggered the loop. I have fixed this so hopefully that shouldn't be a problem anymore :)
Do let me know if you find the problem still exists, or if there are any other bugs you find!
Thanks again for your feedback :D