added tool code and did related refactorings