Rewrote generate_pairs to ldat