Minor change to speed up non-recursive implementation