write function modified