Some refactoring plus style update, and typo correction
EOL