Avoid NPE when using string conversion, simpler code

Fixes #311