make thread function into a proper function