refactored getting groups and departments. implemented non-empty groups fetching