Fix writer, add more tests.