moved write method to mmdwriter, rearranged code