Apply patch from Nathan Kurz