Changed program to loop whenever possible