Refactored connection retry behaviour.