added error handling on several cases
Merge pull request #35 from Galithil/master

added error handling on several cases