templating and more helper function