corrected friends counting function