Fixing a null pointer bug