slightly updated debugging part