Moved code to util.h