Use a linked-list for the task queue instead of an array. Arrays are generally faster, but a linked-list is faster for removing (in the duplicate check).