Move write logic to write_logic