reimplemented write_impl
added test for new write-impl, removed previous write-impl