Fewer calculations and move some stuff to separate method.