Further optimizations and corrections