Refactored to add an 'optimize' param to the state config