Minor refactoring; improve debug output