cleaner (and correct) nesting support

Now we use a stack, the previous version was not correct.
composite definition