Integrated bug fixes from Gary 2.