resolve type error with loop, thanks to pnkfelix