Added Null pointer checks.