move template function to header files, add more const&