add better error handling for missing data