[MOD] Better handling of connections on the main thread and background thread