while-loop almost complete