Fixing possible access to a nil pointer