Change if to while in findAll function