finally functional, mostly right, well see if it actually works