Optimization fixes