second pass, this time without recursion