Change the each() method to a while method