cleanup_output_dir updated to work better with custom templates