Some refactoring and restyling