some optimizations and typo fixes
some fixes