Fixed reference invalidation bug.