Refactor optimizer.