refining tree code