moves save function to templates, provide more common mechanism to define save functions