append refactored to use writeAt