Add tree visualization
Add failing tests
Add debug tracing
Fix `encode`