Tweaked test for better error reporting.
Added a DEBUG flag which can be used to turn on/off the DEBUG details.