Made the connection more thread safe