Handle errors more gracefully