Hi,
if I am not overlooking something here, the function recurse_hierarchy is neither recursive nor will it retrieve the layers for all objects in the scene. It will retrieve the layers for all siblings of the passed node, that were born after that node.
You probably made a mistake copying your code or misunderstood what is meant by recursive.
Cheers,
zipit