Small optimizations and corrections