Threading and writing for client. Untested