It seems like you can save a bit of duplication below by adding something like:

```javascript
var manager = isViewState ? PreferencesManager.stateManager : PreferencesManager;
```

and then just using `manager` below in the two blocks that check for `isViewState`.