closed #4: implemented automatic reconnect