Improve error/invalid data handling