added more efficient threading