refactoring and style changes