Basic error cases handling

Error cases handling is basically improved to especially handle more
NULLPTR cases according to comments fro Max.
Merge pull request #3 from evmarkov/master

Basic error cases handling