Update and optimize.