Causal networks and freedom of choice in Bell's theorem