Clean up renderTemplate function