In the later years of his life, Llywelyn turned his attention to his successor. Welsh law stipulated that illegitimate sons had equal rights with legitimate sons; Llywelyn sought to ensure that Dafydd ap Llywelyn, his legitimate offspring, would inherit Gwynedd in place of his eldest, but illegitimate, son Gruffydd. On Llywelyn's death in 1240, Dafydd sought to secure his position. Dafydd was half English and feared that his pure Welsh half-brother would be able to gather support to overthrow him. Gruffydd was held prisoner in Criccieth Castle, until he was handed over to Henry III of England in 1241, and moved to the Tower of London.