Moved some functions to template