Fixed never-cancelling bug with threads