Optimizations and typo fix