code refactoring and formating