refactore code, no longer write stream, now i have tree before writing, optimized output