Improvement of previous bug fix + extra debugging feature