Connection handling and testing in get_random_connection fixed.