refactoring and style upgrade