Fixed logic to handle non-JSON data