Added error handling for bad data