adding a debug flag and some more appropriate output