Some refactoring, style update, and typo correction