is now templated, added some function