Pull generally useful routines out into tools.c
Fix header include