refactored template setup