factor some crap code out into util.c
add util.[ch]