Optimize changes from PR #2290