move some functions into this package from npctmctree