Added thread synchronization to session object + moved set_session_ptr() to connect()