factor out tree storage to implement stage separately
move TreeStore into separate module