moved some code over to tools.