fix infinite loop when removing array