Fixed broken tests. Writer refactorings