I've been trying to solve this problem of mine for a while now but I'm not really sure how to go about it. 

For example, let's say I have this "tree" in my database:

```
tree4(b(b(l(Apple),l(Banana)), b(l(Orange), l(Pear)))).

```

I want to be able to query the database so as to retrieve the information within each l() and present it in a list. So far I've done this:

```
leaves(l(X), L) :-
    L = X.
leaves(b(X,Y), L) :-
    leaves(X, A),
    leaves(Y, B),
    L = [A, B].

```

I then query the database and it gives me this:

```
?- tree4(T), leaves(T, L).
T = b(b(l(1), l(2)), b(l(3), l(4))),
L = [[1, 2], [3, 4]].

```

The problem with this code is it generates multiple lists nestled within my original one. Is there another way to go about this? Any help would be greatly appreciated!