refine code and make clientmainprogrammtic work