Fix and optimizations