Functioning BT thread code