move some common code out of the cogserver