Extracted methods from update() to make the method much simpler.