Rewritten and fixed lddmc_relprev and lddmc_match