Refactored double recv loop