Refactor DbWriter. Add some methods