add recursive and debug function