Optimization and some cleaning