Syncing with 3.0 branch. Not tested.