Fixed bug revealed by test battery.