Refactor a bit and add tree script.