add group indices and fix small bugs