add debug function and improve output for quiet mode