Added checks for adding and removing security groups