move some code for better readability