Typo; put unset($ig) inside loop.