Refactor the security groups API layer into more discrete components