Make UTF environment detection more robust.

Fixes #125