Fixed #539 in master (for 2.5.0) -- slightly risky change so can't easily backport unfortunately.