As Muscovy regained stability, discontent grew within the serf and peasant populations. Under Alexis Romanov, Mikhail's son, the Code of 1649 divided the Russian population into distinct and fixed hereditary categories. The Code increased tax revenue for the central government, and put an end to nomadism, to stabilize the social order by fixing people on the same land and in the same occupation as their families. Peasants were tied to the land, and townsmen were forced to take on their fathers' occupations. The increased tax burden fell mainly on the peasants, further widening the gap between poor and wealthy. Human and material resources became limited as the government organized more military expeditions, putting even greater strain on the peasants. War with Poland and Sweden in 1662 led to a fiscal crisis, and rioting across the country. Taxes, harsh conditions, and the gap between social classes drove peasants and serfs to flee. Many went to the Cossacks, knowing that the Cossacks would accept refugees and free them.