Cleanup and optimize some tools

Change-Id: Idd52c8a8254a4f9e813aeb44148b13c49e54c376