What trend led to a major shift in the livelihoods of early towns?