improved iteration code, now faster :)