Working. I think. Needs cleanup.

Hacked this to the point where it does what I want for v.0.  Need to
make the code much more modular and readable.