Use inline defers for more readable code
cherry-pick e108a2ffec444c09b3661379a1051fda1f9952cf