rewritten thread fetching logic