moving communication into different threads; handle disconnections TODO