Added Andrew Tesker's "simpler" version
Minor fix in the while loop test