Refactor--removes unneeded while loop