improved comments
fixed last separator of first group getting selected instead of first
avoided unnecessary loop