Implemented class-based optimization.