template functions and algorithms