Fixed crash related to STL when recycling cursors.

Prevented segfault when trying to dereference the iterator after the iterator was removed from the list. It seems that the iterator was invalid after it was erased so we just grab the value before we remove it from the list.