Added better memory management and threading
Added better threading