fixing errors in template functions