fix saveTree function