Implement write()