Judge clears way for Wells legacy deal