Improved string sanitization