Copy changes from 969bbf5 to v3 code