Fix memory leak and few cosmetic changes for static tools