Refactored socket operations and statistics.