fix bugs in csd computation