The first draft of the complete program.

Completely untested.
Rework into packaged app.