refactoring and indentation fixes