Could we use template to implement the two functions?