optimize cl and server , add error handling