Moved security group code to its own function