added multhreaded support