Improved thread handling
Re-organised imports
Improved threads shutdown