Refactoring and style correction