cleanup and add to measure and writ