Refactored layout template functionality