move some common functions into util