Adding Reverse Logic in recursion