private void removeAny(Gameboy gb, List<ListState> listStates, StateBuffer initialStates) {
    HashMap<Integer, ListState> listStateMap = new HashMap<>();
    for (ListState listState : listStates) {
      for (State state : initialStates.getStates()) {
        State s = listState == null ? state : listState.toState(gb, state, false);
        if (!listStateMap.containsKey(s.rngState))
          listStateMap.put(s.rngState, listState);
      }
    }
    listStates.retainAll(listStateMap.values());
  }