Factor templates out of the main page