Many changes and optimizations