Improved template rendering and cleanup process