Use a single function template instead of two separate functions