refactoring of layouts code