main function (client)