Fix threading issues with different threads reading from the queue