Threading and performance improvements