Fix null pointer bug