refine the use of $debug_mode