The first draft of the complete program.

Completely untested.