Optimization and clean up