added a while loop instead of eac()