Do not use list.copy() because of Python 3.2 compatibility
Refactor generation using generic tree traversal