cherry-pick from #5