Some optimizations and typo corrections