Proper shutdown of threadpool
Fixed null branch issue