Split setup_socket_normally() into three other functions