refactor optimizer