Refactoring of template-related functions