Fixed a small bug with threading