templatized some functions