Fixed a possible synchronization issue when removing from the queue