add mass writing
code cleanup