Added some null pointer checks.