updated code, changed while statement from or to and