Added in recent patches from 1.5.6 branch.

non-beta