bug fix, works well but multithreaded doesnt seem to imrove anything