Cleaned up middleware calls in socket handling.