John recognised the growing influence of Prince Llywelyn as a threat to English authority in Wales. King John invaded Gwynedd and reached the banks of the Menai, and Llywelyn was forced to cede the Perfeddwlad, and recognize John as his heir presumptive if Llywelyn's marriage to Joan did not produce any legitimate successors. Succession was a complicated matter given that Welsh law recognized children born out of wedlock as equal to those in born in wedlock and sometimes accepted claims through the female line. By then, Llywelyn had several illegitimate children. Many of Llywelyn's Welsh allies had abandoned him during England's invasion of Gwynedd, preferring an overlord far away rather than one nearby. Welsh lords expected an unobtrusive English crown; but King John had a castle built at Aberystwyth, and his direct interference in Powys and the Perfeddwlad caused many of these Welsh lords to rethink their position. Llywelyn capitalised on Welsh resentment against King John, and led a church-sanctioned revolt against him. As King John was an enemy of the church, Pope Innocent III gave his blessing to Llywelyn's revolt. Early in 1212 Llywelyn had regained the Perfeddwlad and burned the castle at Aberystwyth. Llywelyn's revolt caused John to postpone his invasion of France, and Philip Augustus, the King of France, was so moved as to contact Llywelyn and propose that they ally against the English king, King John ordered the execution by hanging of his Welsh hostages, the sons of many of Llywelyn's supporters, Llywelyn I was the first prince to receive the fealty of other Welsh lords at the 1216 Council of Aberdyfi, thus becoming the de facto Prince of Wales and giving substance to the Aberffraw claims. Dafydd ap Llywelyn 1240–46 On succeeding his father, Dafydd immediately had to contend with the claims of his half-brother, Gruffudd, to the throne. Having imprisoned Gruffudd, his ambitions were curbed by an invasion of Wales led by Henry III in league with a number of the captive Gruffudd's supporters. In August 1241, Dafydd capitulated and signed the Treaty of Gwerneigron, further restricting his powers. By 1244, however, Gruffudd was dead, and Dafydd seems to have benefited from the backing of many of his brother's erstwhile supporters. He was acknowledged by the Pope as Prince of Wales for a time, and defeated Henry III in battle in 1245 during the English king's second invasion of Wales. A truce was agreed