added non-recursive solve