Better error handling, typo fixed.