Moved some util functions around