Improve invalid data handling