refactoring and improving code style