Fix in LD calculation including test that would have detected the bug