Refactoring of the debugging messages.

Please review.
Fixed debug option