templated some of the functions