Optimization and minor changes