Back-ported patches from Tom Hite