Null pointer bug fix