Adding ensure_group
Make sure local variables are assigned blank values otherwise a global var might pop-up
Use a slightly different match
Make the i and n vars local as well
Add the gid and uid to ensure_user