added extra error handling