Fix some typos and refactoring.