Implemented write for leaves
Write for leaves works now