implement 'write' method