add tree code; also resolves #31