fixed: scope of stateManager was function not global