Add safety check to Target::to_string