Changing trace function to template