Add more error checking.
Merge pull request #577 from nZEDb/dev

Add more error checking.