Moved some stuff out to util.c