Various changes and optimizations