Minor refactoring

Removed some code duplication
Use more explicit name
inlined method used only once
Formatting
merge dom setup refactor #544