Optimization and cleaning