Add first batch of tests for tools and fix some bugs found