Added better error handling

Attempted fix for problem reported by Ben: error message thrown when
accessed. I made the error handling code more robust so if there is an
error, it's more specific what happened.