Many thanks for sharing this A & F. I have only skimmed through but will read in detail later.
If I can help in any way just let me know, although you seem to have sussed it out extremely well perhaps some assistance with G-code or the like.
We have some brilliant brains on the forum for this sort of thing half of them don't know how clever they are.