splitting template portion into its own function