Fixed some bugs in security group handling.