Fixes thread issues