Handle non-printable characters properly

Fixes #723