Optimization and more fixes