Improve Thread management