replace template with function