add debug output functions and fix code format