updated for multythread