copy some functions from cvt.