Move dtree code to the plugin