Refactor group check