updated cleanup_output_dir method to work better with custom templates