Fixing null pointer exceptions