changed main to a loop