Minor tweaks

These are small changes, but shouldn't break anything. Just preventing logging if debug=false and exposing the error codes so we don't have to hard code errors.

FYI - this is my first ever pull request with github, so let me know if I screwed something up!