From 1437 to 1439 the king's first cousin Archibald Douglas, 5th Earl of Douglas, headed the government as lieutenant-general of the realm. After his death, and with a general lack of prominent earls in Scotland due to deaths, forfeiture or youth, political power became shared uneasily among William Crichton, 1st Lord Crichton, Lord Chancellor of Scotland (sometimes in co-operation with the Earl of Avondale), and Sir Alexander Livingston of Callendar, who had possession of the young king as the warden of the stronghold of Stirling Castle. Taking advantage of these events, Livingston placed Queen Joan and her new husband, Sir John Stewart, under "house arrest" at Stirling Castle on 3 August 1439. They were released on 4 September only by making a formal agreement to put James in the custody of the Livingstons, agreeing to the queen's relinquishment of her dowry for his maintenance, and confessing that Livingston had acted through zeal for the king's safety.