Updated to be multithreaded