improve message handling (server and client)