connection thread functions added. compiled. not tested yet