Added checks for NPE.

Related to #24.