be a bit more anal about missing prototypes.

This highlighted a bunch of functions that could be made static,
as well as some missing includes.