 Lithuania's laws were codified and reforms enacted in 1529, 1557, 1565–1566 and 1588, gradually making its social, legal and economic system similar to that of Poland, with the expanding role of the middle and lower nobility.Fighting wars with Moscow under Ivan IV and the threat perceived from that direction provided additional motivation for the real union for both Poland and Lithuania.The process of negotiating the actual arrangements turned out to be difficult and lasted from 1563 to 1569, with the Lithuanian magnates, worried about losing their dominant position, being at times uncooperative.