code clean: cache and tree is flexible