Add more complete-program unit test. Fix minor bugs.