Refactored layout preparation.