moved more functions to util.c, split main.c