Bug #1 fixed. Program now terminates reliably.