fixing null pointer bugs -sG