recursive version of LPS