Apply patch from Jakob Fink