move some of code out.