Unstable environments favored flexibility