little code improvements and performance improvements
Merge branch 'cs/#6953-code-quality-improvements'

Close #6953