rewrite 'write_function'