Remove some duplicate code in connection handling

Plus check for more than one redirect.