moved generic functions to tools