First working version.  Very rough, but gets the job done.