major rewrite of tools and detect()