working on recursivity algorithm