added a while loop and a quit condition, as well as fixing it up