Minor fixes and optimizations