extracted methods write and write_line