CollectionWriter refactoring

RUBY-676