Fixed #2. Switched back to a connection per thread and use ping to reopen the connection if it is closed