Add some automated test scripts and fix bugs exposed by them.