added C++ template to more functions