Some minor changes and optimizations