Fixed thread issues