fixing a null pointer bug