Fixing a nil pointer exception