It is not known whether the church was built because of St. Triduana, but the church, a rectangular building, housed her relics, and her cult prospered under the patronage of James III of Scotland. He built a hexagonal chapel royal there, adjacent to the kirk, dedicated to the Virgin Mary and the Holy Trinity, and endowed it a chaplaincy in 1477. It became known as the King's Chapel. Payment for the roof was made in 1486-7. At the same time, he made the kirk a collegiate establishment called the Deanery of Restalrig, and initiated a programme of extension. Originally built on two levels, the surviving lower level of the hexagon was an undercroft for the chapel above. Sometimes referred to as a "well-house", this is probably a misnomer, the flooding being accidental. The lower aisle was used as a burial chamber for the Logan family. James IV added six prebendaries and James V a choir of boys.