finished write function