The former fix for socket initialization was broken. This fixes the "fix" by using the right exit condition for the loops.