Refactor Layout generation