bug fixes in ld.matrix