Refactor the optimizer.