Optimized clear function