Fix and add debug output