bug fix and add debug