           .map { $0.state },
         actionSource
           .mapOmittingNil { $0 as? UuidAction<PreviewTool.Action> }
-          .mapOmittingNil { action in
-            guard let mainWindowState = self.appState.mainWindows[action.uuid] else {
-              return nil
-            }
-
-            return StateActionPair(state: UuidState(uuid: action.uuid, state: mainWindowState),
-                                   action: action.payload,
-                                   modified: false)
-          }
+          .mapOmittingNil { self.mainWindowStateActionPair(for: $0) }
           .transform(by: PreviewToolTransformer(baseServerUrl: baseServerUrl))
           .filter { $0.modified }
           .map { $0.state },
         actionSource
           .mapOmittingNil { $0 as? UuidAction<FileBrowser.Action> }
-          .mapOmittingNil { action in
-            guard let mainWindowState = self.appState.mainWindows[action.uuid] else {
-              return nil
-            }
-
-            return StateActionPair(state: UuidState(uuid: action.uuid, state: mainWindowState),
-                                   action: action.payload,
-                                   modified: false)
-          }
+          .mapOmittingNil { self.mainWindowStateActionPair(for: $0) }
           .transform(by: FileBrowserTransformer())
           .filter { $0.modified }
           .map { $0.state },
         actionSource
           .mapOmittingNil { $0 as? UuidAction<OpenedFileList.Action> }
-          .mapOmittingNil { action in
-            guard let mainWindowState = self.appState.mainWindows[action.uuid] else {
-              return nil
-            }
-
-            return StateActionPair(state: UuidState(uuid: action.uuid, state: mainWindowState),
-                                   action: action.payload,
-                                   modified: false)
-          }
+          .mapOmittingNil { self.mainWindowStateActionPair(for: $0) }
           .transform(by: OpenedFileListTransformer())
           .transform(by: previewTransformer.forOpenedFileList)
           .filter { $0.modified }

  let stateSource: Observable<AppState>
  let actionEmitter = Emitter<Any>()

  init(_ initialState: AppState) {
    let baseServerUrl = URL(string: "http://localhost:\(NetUtils.openPort())")!

    self.appState = initialState

    self.stateSource = self.stateSubject.asObservable()
    let actionSource = self.actionEmitter.observable

      })
      .addDisposableTo(self.disposeBag)

    // MainWindow.State
    Observable
      .of(
        actionSource
          .mapOmittingNil { $0 as? UuidAction<MainWindow.Action> }
          .mapOmittingNil { self.mainWindowStateActionPair(for: $0) }
          .transform(by: MainWindowTransformer())
          .transform(by: previewTransformer.forMainWindow)
          .filter { $0.modified }
