move some code for clarity