Refactored reconnect()