Wrapped up the threading code into its own class.