add small opimization
add multiprocessing support