Improve thread management.