Pieces are now matched to target. Still a wierd issue persists -- some pieces do not get removed. The ones, that have been added to array after an element at the index has been removed.
Source file