new version of recursive-star (more efficient)