Fixed bugs for the AD