macOS mojave, second and third window issue

Hello, I’ve been using a code to open second and third window and it is reliable before Mojave.
Now on Mojave it seems to open windows in an arbitrary order each time I run the software, even if I have them nicely ordered on system preferences -> displays.
Any clue of how to fix it?
Cheers!

#include "ofMain.h"
#include "ofApp.h"

shared_ptr<ofAppBaseWindow> newWindow;
vector <shared_ptr<ofAppBaseWindow> > allWindows;

//========================================================================
int main( ){
	int w = 920;
	int h = 700;
	// WINDOW GUI
	float offset = 80;
	ofGLFWWindowSettings settings;
	settings.setSize(w, h);
	//settings.setPosition(ofVec2f(offset,offset));
	settings.windowMode = OF_WINDOW;
	auto guiWindow = ofCreateWindow(settings);
	//auto guiApp = make_shared<ofGuiApp>();
	auto mainApp = make_shared<ofApp>();
	
	CGDisplayCount displayCount;
	CGDirectDisplayID displays[32];
	CGGetActiveDisplayList(32, displays, &displayCount);
	int numDisplays = displayCount;
	
	for (int a=1; a<numDisplays; a++) {
		int whichDisplay = a;
		int displayHeight = CGDisplayPixelsHigh (displays[whichDisplay]);
		int displayWidth = CGDisplayPixelsWide (displays[whichDisplay]);
		CGRect displayBounds = CGDisplayBounds (displays[whichDisplay]);
		
		ofVec2f pos = ofVec2f(displayBounds.origin.x, displayBounds.origin.y);
		
		settings.setSize(displayWidth, displayHeight);
		settings.setPosition(pos);
		settings.windowMode = OF_FULLSCREEN;
		settings.shareContextWith = guiWindow;
		
		newWindow = ofCreateWindow(settings);
		
		if (a==1) {
			ofAddListener(newWindow->events().draw, mainApp.get(), &ofApp::drawSecondWindow1);
		}
		else if (a==2) {
			ofAddListener(newWindow->events().draw, mainApp.get(), &ofApp::drawSecondWindow2);
		}
		allWindows.push_back(move(newWindow));
	}
	
	ofRunApp(guiWindow, mainApp);
	ofRunMainLoop();	
}