split tree logic into modules