moved logic from chat to client