Move the code from tool.go to a lib in order to allow other programs to use it