Made error handling more consistent.