add more robust template code