Bug #3 fixed. Program now terminates reliably.