the math in the above version has a flaw. it works alright... but...

will fix it later tonight.