Do safer string manipulation via snprintf

Fixes #11