Refactored Optimizer