Adding more error catching code