template function cleanup