Corrected threading implementation.