fixing null pointer bugs