fixing some bugs, and handle the communication between the client and the server