Refactor DebugMessage handling (close #227)