Fixed incorrect thread synchronizations