Code refactoring and style changes