There's lots more work to do here, but this simple program found a couple of problems which I've fixed recently.