Several optimizations, worked more on the smart solver.