...
- add tests (at least for regression) before refactoring
- add type checking to recursive methods
- add visitor or similar pattern to avoid instanceof
- convert println messages to a logger configured with file output
- check for element/type redefinition and fail (might need to support namespaces if it happens)