Isn't having a while loop here more idiomatic?