abstract a map function and correct template error