Fix for #1020. Also clean the jsonp/ajax reconnect logic