Moved utility functions to util.[ch]