Check if security group is nil, fixes #2507

Check if security group is nil, fixes #2507