extract to util.r