refactor layout management