add recursive implementation