Fix writing emc tree