Refactor layout retrieval