Move miscellaneous functions to util.