Adding better error handling