moved some functions to tools.js