implement merged writes, cleanup a lot