Added null pointer check.

to fix issue#58