Costain settles troubled Heads of the Valleys contract