added debug mode

Debug mode is used to print some diagnostic info. Use -d to activate
this mode. It will be deleted by submission.