fixing null pointer bug