when debug flag set, print stack trace to console

I've got myself into a bit of a mess with the original restore for I was using to add features/fix things. So, to make things simpler, I've made a new fork and will manually import my changes one at a time of separate branches and submit them to you.