Moved some functions to util.