Debug messages switch -D added and handling for error..