Clean up some comments in tools.c.

Also do a tiny bit of code cleanup. Really need to do unit tests on these functions.