add threading function (not complete)