Apply patch from Frank Denis