Massive rewrite in preparation for resuming work on ths game.