Re-add null check and switch socket.send to socket.sendall()