move some code around