Updated to be multi-threaded