fix bugs around debug code.