I am still having errors in the modular arithmatic stuff.  Images are screwed up.  I need to carefully go through all the trig.