Reworked threading to use daemon threads where appropriate.