helpers, and tree optimization