Added the 'whileEach' function