added readline function
changed do loop to while loop