Make sure the connect happens in the outermost if block