Added stability test.
Moved reconnecting into a separate loop.