Imrpoved the template code