refactor debug.cpp