Passage: During the war with France, William tried to improve his position by marrying, in 1677, his first cousin Mary, elder surviving daughter of the Duke of York, later King James II of England (James VII of Scotland). Mary was eleven years his junior and he anticipated resistance to a Stuart match from the Amsterdam merchants who had disliked his mother (another Mary Stuart), but William believed that marrying Mary would increase his chances of succeeding to Charles's kingdoms, and would draw England's monarch away from his pro-French policies. James was not inclined to consent, but Charles II pressured his brother to agree. Charles wanted to use the possibility of marriage to gain leverage in negotiations relating to the war, but William insisted that the two issues be decided separately. Charles relented, and Bishop Henry Compton married the couple on 4 November 1677. Mary became pregnant soon after the marriage, but miscarried. After a further illness later in 1678, she never conceived again.Throughout William and Mary's marriage, William had only one reputed mistress, Elizabeth Villiers, in contrast to the many mistresses his uncles openly kept.

Question: what did William try to do to improve his relationship during the war with France?
marrying, in 1677, his first cousin Mary