cherry-pick of loz' cleanup of code smells