Fixed error handling.
Merge remote-tracking branch 'origin/hj/fix-error-handling'