recursive algorithm to get a consolidated report