Refactoring and style changes