Applying @joezuntz's patch from #38