Added error handling in read_data