Updated with multithreading functionality