do this in one pass, but actually same cost as two pass