Handle invalid strings properly