Fixed error handling in loadData()