Worker for the multithreading logic