Error handling

An attempt to get error handling straightened out a bit.