Split SocketMain into functions