Added multithread support.