improve debug / error logging a bit, and there are a lot of reformats tagging along.
Merge branch 'master' into api-cleanup