while-loops and tests fixed