Refactors main template system.