Fix-up diagnostic output to check debug flag and use of stdout