Fix error handling in a number of places
v0.040

          Fix error handling in a number of places