Transform Virtual Stack: remove unused imports and add buffer closings.