move function templates to header files
implement function template instantiation

but it has so many bugs... (moudameda)