Further refactoring for the security groups api layer