Split layout-generation code into module