The following line "IF B\Snap=false" is causing you the error. You should either delete the type instance 'B' last, or set a flag to delete the instance and do so at the end of your loop
When it gets to the line " if B\snap=false " b no longer exists.
When it gets to the line " if B\snap=false " b no longer exists.