Rewrite using TCPSocket, proper JSON generation