generating and saving templates