Replaced each method by while