Iterate over the levels instead of recursing