Typo fixes and minor code refactorings