I wonder if this might be useful to be used/shared in the MacOS code too?