Refactored threaded code to be less CPU intensive.