Reapply PR #4113 (removed via #4175)
Land #4178, remerge of #4113