Added null pointer checks.