Refactored threads.
Preparing for cross platform threading.